const sql = "select * from line;";

const allline = (connection, req, res) => {
  connection.query(sql, (err, result) => {
    var data = null;

    if ( err ) {
      console.error(err);
      res.status(200).json({
        status: "fail",
        data: data,
      });
      return;
    } else {
      data = [];

      result.forEach(item => {
        data.push({
          id: item.id,
          name: item.name,
        });
      });

      res.status(200).json({
        status: "success",
        data: data,
      });
    }
  });
}

module.exports = allline;